<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>09盒子模型padding和margin对比</title>
    <style>
        .parent {
            height: 300px;
            width: 300px;
            background-color: pink;

        }

        .son {
            height: 100px;
            width: 100px;
            background-color: skyblue;
        }

        .parent-first {
            padding-top: 10px;
        }

        .parent-second {
            background-color: antiquewhite;
            /* 给父元素设置边框，可以防止子元素的 margin-top 传递问题 */
            border: 1px solid black;
        }


        .son-second {
            margin-top: 10px;
            background-color: purple;
        }
    </style>
</head>

<body>

    <div class="parent parent-first">
        <div class="son son-first">
            <h2>方式一:给父盒子设置padding,更符合语义化，盒子和自己内容之间的距离</h2>
        </div>
    </div>
    <hr>
    <div class="parent parent-second">
        <div class="son son-second">
            <h2>方式二：给子盒子设置margin(会造成margin传递问题，将子盒子的margin传递给了父盒子)</h2>

        </div>
    </div>
</body>

</html>